package com.foreveross.crawl.common.domain;

import java.util.Date;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.dayatang.domain.InstanceFactory;

import com.foreveross.crawl.common.jpa.annontation.HBaseColumn;

/**
 * hbase映射的抓取数据存储实体
 * <p>对应hbase的CRAWL_DATAS表
 * @author xiangsf 
 * @since 2013-1-29
 */
@javax.persistence.Table(name="CRAWL_PF_SOURCE_DATA")
public class GrapSourceDataEntity extends BaseHBaseEntity{
	/**
	 * 
	 */
	private static final long serialVersionUID = 7185767667135390345L;

	/**
	 * 抓取的条件
	 */
	@HBaseColumn(qualifier="CONDITIONS",family="CONTENTS")
	private String conditions;
	/**
	 * 抓取到的内容
	 */
	@HBaseColumn(qualifier="CONTENTS",family="CONTENTS")
	private String contents;
	/**
	 * 抓取到的扩展内容（如有）
	 */
	@HBaseColumn(qualifier="EXT_CONTENTS",family="EXT_CONTENTS")
	private String extContents;
	
//	private String channelId ;
	/**
	 * 入库时间
	 */
	@HBaseColumn(qualifier="CREATE_TIME",family="EXT_CONTENTS", format="yyyy-MM-dd HH:mm:ss")
	private Date createTime = new Date();
	
	public GrapSourceDataEntity(String conditions, String contents,
			String extContents) {
		super();
		this.conditions = conditions;
		this.contents = contents;
		this.extContents = extContents;
	}

	public String getContents() {
		return contents;
	}
	public void setContents(String contents) {
		this.contents = contents;
	}
	public String getExtContents() {
		return extContents;
	}
	public void setExtContents(String extContents) {
		this.extContents = extContents;
	}
	
	public String getConditions() {
		return conditions;
	}
	public void setConditions(String conditions) {
		this.conditions = conditions;
	}
	
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	

	public String generateRowKey() {
		// 帅哥说改成这样
		// 渠道(往|返)航线航班时间(yyyyMMdd)抓取时间(yyyyMMddHHmmss)五位随机数
		// 保存网页数据的rowkey
		// eg: 00001_CANPEK_20140320_201403181600_12345

		return new StringBuilder()
				.append(this.conditions)
				.append("_")
				.append(StringUtils.leftPad(String.valueOf(RandomUtils.nextInt(99999)), 5, '0'))
				.toString();
	}

	public IGrapSourceDataRepository getGrapSourceDataReposity() {
		return InstanceFactory.getInstance(IGrapSourceDataRepository.class);
	}
	
	
}
